﻿<!--#include file="../Include/Config.asp"-->
<%
dim action,Survey_id,Question_type,Question_content
dim Question_answer,Question_result,Question_img
action=request.QueryString("action")
Survey_id=request.Form("Survey_id")
Question_type=request.Form("Question_type")
Question_content=request.Form("Question_content")
Question_answer=request.Form("Question_answer")
Question_result=request.Form("Question_result")
'response.Write(Question_answer)
'response.End()
select case action
case "addnew"
Question_img=creatString(ubound(split(Question_result,",")),"null","&")'产生Question_img
sql="select * from question"
rs.open sql,conn,1,3
rs.addnew
rs("Question_type")=Question_type
rs("Question_content")=Question_content
rs("Question_answer")=Question_answer
rs("Question_result")=Question_result
rs("Question_img")=Question_img
rs("survey_id")=survey_id
rs.update

'Question_id=rs("Question_id")
'response.Write(Question_id)
'response.End()
rs.close
'将添加的题目添加到问卷的题目列表中

set rs_q=server.CreateObject("adodb.recordset")
sql_q="select * from question where survey_id='"&Survey_id&"' order by Question_id asc"
rs_q.open sql_q,conn,1,1
rs_q.movelast
Question_id=rs_q("Question_id")
rs_q.close
set rs_q=nothing


sql="select * from survey where Survey_id="&Survey_id
rs.open sql,conn,1,3
if rs("Survey_content")<>"" then
rs("Survey_content")=rs("Survey_content")&","&Question_id
else
rs("Survey_content")=Question_id
end if
rs.update
rs.close
call ShowAlert("题目添加完成","QuestionAdd.asp?Survey_id="&Survey_id&"")
case "edit"
Survey_id=request.QueryString("Survey_id")
Question_id=request.QueryString("Question_id")
sql="select * from question where Question_id="&Question_id
rs.open sql,conn,1,3
if ubound(split(rs("Question_result"),","))<>ubound(split(Question_answer,"&")) then'题目数量减少了
rs("Question_result")=creatString(ubound(split(Question_answer,"&")),"0",",")
rs("Question_img")=creatString(ubound(split(Question_answer,"&")),"null","&")
end if
rs("Question_content")=Question_content
rs("Question_answer")=Question_answer
rs.update
rs.close
call ShowAlert("题目修改完成","QuestionEdit.asp?Survey_id="&Survey_id&"&Question_id="&Question_id&"")

case "jd"
jd_id=replace(request.Form("jd")," ","")
Question_id=request.QueryString("Question_id")
if jd_id="" then
	sql="select * from question where Question_id="&Question_id
	rs.open sql,conn,1,3
	if rs.eof then
	    call ShowAlert("参数错误","")
	else
		rs("Question_jdtz")=""
		rs.update
	end if
	call ShowAlert("题目修改完成,未设置任何截断","")
else
	jd_id=split(jd_id,",")
	sql="select * from question where Question_id="&Question_id
	rs.open sql,conn,1,3
	if rs.eof then
	    call ShowAlert("参数错误","")
	else
		if rs("Question_type")=5 then
			rs("Question_jdtz")="over"
			rs.update
		else

			Question_result=split(rs("Question_result"),",")
			Question_jdtz=rs("Question_jdtz")
			redim jd_id_new_arr(ubound(Question_result))
			if Question_jdtz<>"" then
				Question_jdtz=split(Question_jdtz,"&")
				for i=0 to ubound(Question_jdtz)
					jd_id_new_arr(i)=Question_jdtz(i)	
				next
			else
				for i=0 to ubound(Question_result)
					jd_id_new_arr(i)="null"		
				next
			end if	
			for each jd_id_item in jd_id
				jd_id_new_arr(jd_id_item)="over"
			next
			for i=0 to ubound(Question_result)
				if jd_id_new_str="" then
					jd_id_new_str=jd_id_new_arr(i)
				else
					jd_id_new_str=jd_id_new_str&"&"&jd_id_new_arr(i)		
				end if
			next
			rs("Question_jdtz")=jd_id_new_str
			rs.update
		end if	
	end if
    rs.close'截断保存后，将问卷中的跳转截断标示修改
	Survey_id=request.QueryString("Survey_id")
	sql="select Survey_jdtz from survey where Survey_id="&Survey_id
	rs.open sql,conn,1,3
		if rs.eof then
			Call ShowAlert("参数错误","")
		else
			rs("Survey_jdtz")=1
			rs.update
		end if
	rs.close
	call ShowAlert("题目修改完成,共设置"&ubound(jd_id)+1&"个截断","")
end if

case "tz"
tz_id=replace(request.Form("check_box")," ","")
tz_id_text=replace(request.Form("check_box_text")," ","")
Question_id=request.QueryString("Question_id")
'Call ShowAlert(tz_id_text,"")
'Call ShowAlert(tz_id_text,"")'
'response.End()
if tz_id="" then'只判断tz_id即可，tz_id_text不可能为空
	sql="select * from question where Question_id="&Question_id
	rs.open sql,conn,1,3
	if rs.eof then
	    call ShowAlert("参数错误","")
	else
		rs("Question_jdtz")=""
		rs.update
	end if
	call ShowAlert("题目修改完成,未设置任何跳转","")
else
	tz_id=split(tz_id,",")
	tz_id_text=split(tz_id_text,",")
	sql="select * from question where Question_id="&Question_id
	rs.open sql,conn,1,3
	if rs.eof then
	    call ShowAlert("参数错误","")
	else
		if rs("Question_type")=5 then
			rs("Question_jdtz")=tz_id_text(ubound(tz_id_text))
			rs.update
		else
			Question_result=split(rs("Question_result"),",")
			Question_jdtz=rs("Question_jdtz")
			redim tz_id_new_arr(ubound(Question_result))'redim()声明的是最大下标，
			if Question_jdtz<>"" then
				Question_jdtz=split(Question_jdtz,"&")'从数据库读取已存在Question_jdtz的信息
				for i=0 to ubound(Question_jdtz)
					tz_id_new_arr(i)=Question_jdtz(i)	
				next
			else
				for i=0 to ubound(Question_result)
					tz_id_new_arr(i)="null"		
				next
			end if	
			for j=0 to ubound(tz_id)
				tz_id_new_arr(tz_id(j))=tz_id_text(tz_id(j))
			next
			for i=0 to ubound(Question_result)
				if tz_id_new_str="" then
					tz_id_new_str=tz_id_new_arr(i)
				else
					tz_id_new_str=tz_id_new_str&"&"&tz_id_new_arr(i)		
				end if
			next
			rs("Question_jdtz")=tz_id_new_str
			rs.update
		end if
	end if
    rs.close'截断保存后，将问卷中的跳转截断标示修改
	Survey_id=request.QueryString("Survey_id")
	sql="select Survey_jdtz from survey where Survey_id="&Survey_id
	rs.open sql,conn,1,3
		if rs.eof then
			Call ShowAlert("参数错误","")
		else
			rs("Survey_jdtz")=1
			rs.update
		end if
	rs.close	
	call ShowAlert("题目修改完成,共设置"&ubound(tz_id)+1&"个跳转","")
end if

case else response.Write("参数错误")

end select
%>
